package org.lex.game.sudoku.model.visitor;

import org.lex.game.sudoku.model.SudokuModel;

public final class NumberCountVisitor implements ModelVisitor<Integer> {
	private final int targetNumber;
	private int numberCount = 0;

	public NumberCountVisitor(int targetNumber) {
		this.targetNumber = targetNumber;
	}

	@Override
	public VisitResult visit(SudokuModel model, int row, int col, int num) {
		if (this.targetNumber == num) {
			this.numberCount++;
		}
		return VisitResult.CONTINUE;
	}

	@Override
	public Integer finish() {
		return this.numberCount;
	}
}